﻿@using admin.Model
@{
    ViewData["Title"] = "AuthorList";
    Layout = "~/Views/Shared/_SubMenuLayout.cshtml";
    var authors = Model as List<authorBookFor>;
}

<title>作者列表</title>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 作者管理 <span class="c-gray en">&gt;</span> 作者列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a href="javascript:;" onclick="author_batch_del('/Home/AuthorDelB')" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
        </span>
        <span class="r">共有数据：<strong>@authors.Count</strong> 条</span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-hover table-bg table-sort">
            <thead>

                <tr class="text-c">
                    <th width="4%"><input type="checkbox" name="" value=""></th>
                    <th width="15%">作者ID</th>
                    <th width="12%">作者名</th>
                    <th width="12%">电话</th>
                    <th width="">地址</th>
                    <th width="6%">合同</th>
                    <th width="8%">出书申请</th>
                    <th width="8%">已出版书</th>
                    <th width="10%">操作</th>
                </tr>
            </thead>
            <tbody>
                @for (int i = 0; i < authors.Count; i++)
                {
                    <tr class="text-c">
                        <td><input type="checkbox" value="@authors[i].author.Id" name="authorChk"></td>
                        <td>@authors[i].author.Id</td>
                        <td><a title="查看作者信息" onclick="author_show('作者详细信息','/Home/AuthorShow','500','350','@authors[i].author.Id')" href="javascript:;">@authors[i].author.Name</a></td>
                        <td>@authors[i].author.Phone</td>
                        <td>@authors[i].author.Address</td>
                        @if (authors[i].author.IsContact.Equals("1"))
                        {
                            <td>已签</td>
                        }
                        else
                        {
                            <td>未签</td>
                        }
                        <td><a title="查看作者出书申请" onclick="author_book_for('作者出书申请信息','/Home/AuthorBookFor','@authors[i].author.Name','@authors[i].bookapply')" href="javascript:;">@authors[i].bookapply</a></td>
                        <td><a title="查看作者已出版图书" onclick="author_book_outed('作者已出版图书信息','/Home/AuthorBookOuted','@authors[i].author.Id','@authors[i].booklist')" href="javascript:;">@authors[i].booklist</a></td>
                        <td class="td-manage">
                            <a title="编辑" href="javascript:;" onclick="author_edit('编辑作者信息','/Home/AuthorEdit','500','350','@authors[i].author.Id')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe60c;</i></a>
                            <a style="text-decoration:none" class="ml-5" onClick="author_reset_psd('/Home/AuthorResetPassword','@authors[i].author.Id')" href="javascript:;" title="重置密码"><i class="Hui-iconfont">&#xe63f;</i></a>
                            <a title="删除" href="javascript:;" onclick="author_del(this,'/Home/AuthorDel','@authors[i].author.Id')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
</div>


<script type="text/javascript">

    //作者-出书申请-查看
    function author_book_for(title, url, name, count) {
        if (count == "0") {
            layer.msg('该作者暂时没有出书申请哦！', { icon: 5, time: 2000 });
            return;
        }
        else {
            url = url + '?name=' + name;
            var index = layer.open({
                type: 2,
                title: title,
                content: url
            });
            layer.full(index);
        }
    }

    //作者-已出版书-查看
    function author_book_outed(title, url, id, count) {
        if (count == "0") {
            layer.msg('该作者暂时没有出版过图书哦！', { icon: 5, time: 2000 });
            return;
        }
        else {
            url = url + '?id=' + id;
            var index = layer.open({
                type: 2,
                title: title,
                content: url
            });
            layer.full(index);
        }
    }

    /*作者-编辑*/
    function author_edit(title, url, w, h, id) {
        url = url + '?id=' + id;
        layer.open({
            type: 2,
            area: [w + 'px', h + 'px'],
            fix: false, //不固定
            maxmin: true,
            shade: 0.4,
            title: title,
            content: url
        });
    }
    /*作者重置密码*/
    function author_reset_psd(url, id) {
        layer.confirm('确认要重置密码为"123456"吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: url,
                data: {
                    "authorid": id
                },
                success: function (response) {
                    if (response == "ok")
                        layer.msg('密码已重置!', { icon: 1, time: 3000 });
                    else
                        layer.msg('密码重置失败! 请稍后再试', { icon: 5, time: 3000 });
                    //location.reload();
                },
                error: function (response) {
                    layer.msg('密码重置失败! 请稍后再试', { icon: 5, time: 3000 });
                    //location.reload();
                },
            });
        });
    }

    /*作者-详情*/
    function author_show(title, url, w, h, id) {
        url = url + '?id=' + id;
        layer_show(title, url, w, h);
    }

    /*作者-删除*/
    function author_del(obj, url, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: url,
                data: {
                    "authorid": id
                },
                success: function (response) {
                    if (response == "ok") {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!', { icon: 1, time: 1000 });
                    }
                    else 
                        layer.msg('删除失败! ', { icon: 5, time: 3000 });
                },
                error: function (response) {
                    layer.msg('删除失败!', { icon: 5, time: 3000 });
                },
            });
        });
    }

    //作者批删除
    function author_batch_del(url) {
        var checkedNum = $("input[name='authorChk']:checked").length;
        if (checkedNum == 0) {
            layer.msg('请选择至少一项！', { icon: 1, time: 2000 });
            return;
        }
        layer.confirm('确定要删除所选项目？', function (index) {
            var checkedList = new Array();
            $("input[name='authorChk']:checked").each(function () {
                checkedList.push($(this).val());
            });
            $.ajax({
                type: "POST",
                url: url,
                data: { 'delitems': checkedList.toString() },
                success: function (result) {
                    if (result == "ok") {
                        $("input[name='authorChk']:checked").each(function () {
                            $(this).parent("tr").remove();
                        });
                        $("[name ='authorChk']:checkbox").attr("checked", false);
                        layer.msg('已删除!', { icon: 1, time: 3000 });
                        window.location.reload();
                    }
                    else
                        layer.msg('无法删除所选中的作家！', { icon: 5, time: 3000 });
                },
                error: function (response) {
                    layer.msg('删除失败! 请稍后再试', { icon: 5, time: 3000 });
                },
            });
        });
    }

</script>